
import { createSelector } from '@ngrx/store';

import { MapState, MarkersState } from '../reducers';
import { getMapState } from './map.selector';

import { Marker } from '../../models';

const getMarkerState = createSelector(getMapState, (state: MapState) => state.marker);

const getMarkerEntities = createSelector(getMarkerState, (state: MarkersState) => state.entities);

const getAllMarker = createSelector(getMarkerEntities, (entities: { [id: number]: Marker }) => {
    return Object.keys(entities).map(id => entities[id]);
});

const getLastAdd = createSelector(getMarkerState, (state: MarkersState) => state.lastAdd);

const getLastRemove = createSelector(getMarkerState, (state: MarkersState) => state.lastRemove);

const getClearMarkers = createSelector(getMarkerState, (state: MarkersState) => state.clear);

export const markersSelector = {
    getMarkerState,
    getMarkerEntities,
    getAllMarker,
    getLastAdd,
    getLastRemove,
    getClearMarkers
}